<?php

namespace app\controllers\admin;


use app\commands\ErrorMsg;
use app\commands\Helper;
use app\commands\Validator;
use app\Services\admin\RoomService;
use yii\web\Controller;


class RoomController extends Controller
{
    public $req = array();
    public $user = array();

    /**
     * 安全 校验 屏蔽
     * 预处理  权限等等操作处理
     */
    public function beforeAction($action){
        $this->req = Helper::in(array_merge($_POST, $_GET));
        $this->user = Helper::checksign($this->req);
        unset($this->req['token']);
        return true;
    }

    /**
     * 节目管理列表
     */
    public function actionProgramList(){
        $req = $this->req;
        $res = RoomService::getInstance()->getProgramList($req);
        Helper::right_out($req,$res);
    }

    /**
     * 节目详情
     */
    public function actionProgramInfo(){
        $req = $this->req;
        # 请求参数验证
        $rules = array(
            'ID'        => "required|integer",
        );
        Validator::validator($req, $rules,ErrorMsg::ERROR_MSG);
        $res = RoomService::getInstance()->getProgramInfo($req['ID']);
        Helper::right_out($req,$res);
    }

    /**
     * 保存节目设置
     */
    public function actionSaveProgram(){
        $req = $this->req;
        # 请求参数验证
        $rules = array(
            'ID'        => "required",
            'Activity'  => "required|in:0,1",
            'host'      => "required|in:0,1",
            'type'      => "required|in:normal,reporter,VIP"
        );
        Validator::validator($req, $rules,ErrorMsg::ERROR_MSG);
        $res = RoomService::getInstance()->saveProgram($req);
        Helper::right_out($req,$res);
    }

    /**
     * 新增节目
     */
    public function actionAddProgram(){
        $req = $this->req;
        # 请求参数验证
        $rules = array(
            'name'        => "required",
        );
        Validator::validator($req, $rules,ErrorMsg::ERROR_MSG);
        $res = RoomService::getInstance()->addProgram($req['name']);
        Helper::right_out($req,$res);
    }

}
